import fs from 'node:fs'
import path from "node:path";

// 获取当前子项目路径
const packagePath = process.cwd()
// 获取当前publish目录路径
const publishPath = path.join(packagePath, '/publish')
// 获取当前dist目录路径
const publishDistPath = path.join(publishPath, '/dist')
const distPath = path.join(packagePath, '/dist')
// 判断是否存在dist目录
const isExistDist = fs.existsSync(path.join(packagePath, '/publish/dist'));
if(isExistDist) {
    fs.rmSync(publishDistPath, {
        recursive: true
    })
}
fs.renameSync(distPath, path.join(publishPath, path.basename(distPath)))

const mainPackageJson = JSON.parse(fs.readFileSync(path.join(packagePath, '/package.json'), 'utf-8'))
const minorPackageJson = JSON.parse(fs.readFileSync(path.join(publishPath, '/package.json'), 'utf-8'))
minorPackageJson.version = mainPackageJson.version
fs.writeFileSync(path.join(publishPath, '/package.json'), JSON.stringify(minorPackageJson, null, 2))
